package com.tywj.panda.travel.tool

import com.tywj.lib.core.common.util.TimeUtil

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/7/16
 *     desc   :手续费计算
 *     0 -1小时：不能退 服务器判断1-10小时：百分之10（舍弃小数点）10+：全退
 *     version: 2.0.0
 * </pre>
 */

object ServiceFeeTool {
    fun getFee(price: Int, busTime: String): Int {
        //计算时间范围
        val durationTime = TimeUtil.string2Millis(busTime, TimeUtil.PATTERN_DAY_HH_MM) - System.currentTimeMillis()
        //时间差
        val hours = (durationTime / (1000 * 60 * 60)).toInt()

        return when {
            //已过期
            (hours < 0) -> {
                0
            }
            // 1<=hours<=10
            (hours in 1..10) -> {
                (price * 0.9).toInt()
            }
            //其余时间全款退
            else -> price
        }
    }
}